<template>
  <el-card shadow="hover">
    <div class="header">
      <el-button type="primary" @click="handleAdd">新增学生</el-button>
      <el-input
        placeholder="搜索学生"
        style="width: 200px; margin-left: 10px"
        v-model="searchText"
      ></el-input>
    </div>
    <el-table :data="studentList" style="width: 100%; margin-top: 20px">
      <el-table-column prop="id" label="学号" width="120"></el-table-column>
      <el-table-column prop="name" label="姓名" width="120"></el-table-column>
      <el-table-column prop="gender" label="性别" width="80"></el-table-column>
      <el-table-column prop="class" label="班级"></el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
export default {
  name: 'StudentManagement',
  data() {
    return {
      searchText: '',
      studentList: [
        {
          id: '1001',
          name: '张三',
          gender: '男',
          class: '计算机1班'
        },
        {
          id: '1002',
          name: '李四',
          gender: '女',
          class: '计算机2班'
        }
      ]
    }
  },
  methods: {
    handleAdd() {
      this.$message.info('新增学生')
    },
    handleEdit(row) {
      this.$message.info(`编辑学生 ${row.name}`)
    },
    handleDelete(row) {
      this.$confirm(`确定删除学生 ${row.name}?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$message.success('删除成功')
        })
        .catch(() => {})
    }
  }
}
</script>

<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}
</style>